const shareUtil = require('../../../utils/shareUtil.js');
const app = getApp();

Page({
    data: {
        imageInfo: [],
        canvasWidth: 1800,
        canvasHeight: 1800,
        systemHeight: 0,
        systemWidth: 0,
        showImage: {
            url: "",
            width: 0,
            height: 0
        },
        hidden: false
    },
    onLoad: function(e) {
        var t = this;
        t.setData({
            imageInfo: JSON.parse(e.imageInfo)
        }), wx.getSystemInfo({
            success: function(e) {
                t.setData({
                    systemWidth: e.windowWidth,
                    systemHeight: e.windowHeight
                });
            }
        }), console.log(t.data.imageInfo), wx.showLoading({
            title: "给我点时间",
            mask: true
        }), t.connectImage();
    },
    compressImg: function(e, t) {
        wx.compressImage({
            src: e,
            quality: 20,
            success: function(e) {
                t(e.tempFilePath);
            },
            fail: function(a) {
                t(e);
            }
        });
    },
    connectImage: function() {
        for (var e = this, t = wx.createCanvasContext("draw", e), a = e.data.imageInfo, n = 0, i = 0, s = 0; s < 9; s++) 3 == s && (n = 0, 
        i = 600), 6 == s && (n = 0, i = 1200), t.drawImage(a[s].url, n, i, 600, 600), n += 600;
        t.draw(), setTimeout(function(t) {
            wx.canvasToTempFilePath({
                canvasId: "draw",
                success: function(t) {
                    console.log(t.tempFilePath), e.compressImg(t.tempFilePath, function(t) {
                        e.setData({
                            "showImage.url": t,
                            hidden: true
                        }), e.setShowImage(t), wx.hideLoading();
                    });
                },
                fail: function(e) {
                    connsole.log(e);
                }
            }, e);
        }, 500);
    },
    previewImage: function(e) {
        var t = [];
        t.push(this.data.showImage.url),
         wx.previewImage({
            current: t[0],
            urls: t
        });
    },
    saveImage: function() {
        1 != app.getJur() && wx.saveImageToPhotosAlbum({
            filePath: this.data.showImage.url,
            success: function() {
                wx.showToast({
                    title: "保存成功",
                    icon: "none"
                });
            }
        });
    },
    setShowImage: function(e) {},
    onShareAppMessage:shareUtil.shareConfig,
    onShareTimeline:shareUtil.shareConfig,
});